/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dojotec.biblioteca.jsf.domain;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author Alan Almeida
 */
@Entity
@Table(name = "usuario")
@NamedQueries({
    @NamedQuery(name = "usuario.buscarTodos", query = "SELECT u FROM Usuario u"),
    @NamedQuery(name = "usuario.buscarPorId", query = "SELECT u FROM Usuario u WHERE u.id = :id"),
    @NamedQuery(name = "usuario.validarUsuario", query = "SELECT u FROM Usuario u WHERE u.email = :email and u.password = :password")
})
public class Usuario implements Serializable {
    @Id 
      @SequenceGenerator( name = "usuario_id", sequenceName = "usuario_seq", allocationSize = 1 )  
      @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "usuario_id" )
      @Column( name = "id", nullable = false )
    private Long id;
    @Column(name = "nome", nullable = false)
    private String nome;
    @Column(name = "password", nullable = false)
    private String password;
    @Column(name = "email", nullable = false)
    private String email;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "usuario")
    private Collection<Emprestimo> emprestimos;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "usuario")
    private Collection<Reserva> reservas;
   
    public Usuario() {
    
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }    

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Collection<Reserva> getReservaCollection() {
        return reservas;
    }

    public void setReservaCollection(Collection<Reserva> reservas) {
        this.reservas = reservas;
    }

    public Collection<Emprestimo> getEmprestimos() {
        return emprestimos;
    }

    public void setEmprestimos(Collection<Emprestimo> emprestimos) {
        this.emprestimos = emprestimos;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Usuario)) {
            return false;
        }
        Usuario other = (Usuario)object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return String.valueOf(id);
    }

}
